package com.example.qihuibao.module.login

import android.os.Bundle
import com.example.qihuibao.base.BaseActivity
import com.example.qihuibao.databinding.ActivityLoginBinding
import com.example.qihuibao.module.setting.SettingActivity

class LoginActivity : BaseActivity<ActivityLoginBinding>(ActivityLoginBinding::inflate) {
    private val sb = StringBuilder()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        checkAppVersion()
//        viewBinding.btnSendBroadcast.visibility = if (Config.isServerStation) View.VISIBLE else View.GONE
        viewBinding.ivSettings.setOnClickListener { start(this, SettingActivity::class.java) }
//        viewBinding.btnSendBroadcast.setOnClickListener {
//            sb.setLength(0)
//            viewBinding.tvCode.text = sb.toString()
//            Thread {
//                ServerUtil.sendUDPBroadcast()
//            }.start()
//        }
        //listener socket
//        Thread {
//            while (true) {
//                ServerUtil.receiveUDPBroadcast() {msg, ip ->
//                    sb.append(msg)
//                    sb.append("-")
//                    sb.append(ip)
//                    sb.append("\n")
//                    runOnUiThread {
//                        viewBinding.tvCode.text = sb.toString()
//                    }
//                }
//            }
//        }.start()
    }

    override fun onResume() {
        super.onResume()
        getQRCode {
            viewBinding.tvCode.text = "login:$it"
        }
    }
}